<template lang="jade">

  div.return-bar(@click="back()")
    i.iconfont &#xe668;
    {{header_txt}}


  div.detail-page
    section.form(v-show="typeId!=5")
      div.postForm
        input.money(type="text", value="500000", v-model="rdeposit",placeholder="请输入1万的整数倍数，最低50万元" )
        input(type="hidden",name="borrow_nid",v-model="groupId")
        span.rmb 元
        ul.cbox
          li.balance
            span 可用余额￥
              b {{balance}}
              元
          li.btn
            input.goPay(@click="book()", value="立即投标")


  div.detail-info.bottom_space

    div(v-if="typeId == 1")
      header 借款人信息
      article.content
        div 姓名：{{items.borrowinfo.name}}
        //div 身份证：{{items.borrowinfo.idcard}}
        div 姓别：{{items.borrowinfo.sex}}
        div 年龄：{{items.borrowinfo.age}}
        //div 婚姻状况：{{items.borrowinfo.marriage}}
        //div 户籍：{{items.borrowinfo.census_register}}
        //div 月收入：{{items.borrowinfo.income}}
        //div 职位：{{items.borrowinfo.position}}
        //div 资产状况：{{items.borrowinfo.asset}}
        div 现居地：{{items.borrowinfo.address}}

      header 借款用途
      article.content 客户急需一笔资金用于生意周转。

      header 还款来源
      article.content {{items.borrowinfo.source}}

      header 合同模板
      article.content
        div 借款人合同
        a(href="http://www.uximoney.com/upload/files/group/1.pdf") 01.借款合同
        a(href="http://www.uximoney.com/upload/files/group/2.pdf") 02.抵押合同
        a(href="http://www.uximoney.com/upload/files/group/3.pdf") 03.居间合同
        a(href="http://www.uximoney.com/upload/files/group/4.pdf") 04.委托书
        div &nbsp;
        div 出资方合同
        a(href="http://www.uximoney.com/upload/files/group/5.pdf") 01.有喜财富房利宝居间服务协议
        a(href="http://www.uximoney.com/upload/files/group/6.pdf") 02.异地投资人公证委托书模板


    div(v-if="typeId == 2")
      header 抵押物信息
      article.content
        div 项目名称：{{items.abstract1.name}}
        div 评估总价：{{items.assess.assess_val}} 万元
        div 评估单价：{{items.assess.assess_price}} 万元/㎡
        div 借款金额：{{items.abstract1.account}}
        div 抵押率：{{items.abstract1.rate}}万元

      header 房屋信息
      article.content
        div 地址：{{items.apply.house_number}}
        div 类型：{{items.apply.house_type}}
        div 建筑面积：{{items.assess.house_area}}
        div(v-if =" items.assess.house_orientation!='' && items.assess.house_orientation!='0' && items.assess.house_orientation!= null " ) 楼层：{{items.assess.house_floor}}
        div(v-if =" items.assess.house_orientation!='' && items.assess.house_orientation!='0' && items.assess.house_orientation!= null " ) 朝向：{{items.assess.house_orientation}}
        div(v-if =" items.assess.fitment_status!='' && items.assess.fitment_status!='0' && items.assess.fitment_status!=null  " ) 装修情况：{{items.assess.fitment_status}}

      header 相关图片
      article.content

        div.pic
          div.img(style="background: url({{items.assess.property_guise}}) no-repeat center center;background-size:cover;")
            a(href="{{items.assess.property_guise}}",target="_blank")
            span 小区实景图

          div.img(style="background: url({{items.assess.traffic_map}}) no-repeat center center;background-size:cover;")
            a(href="{{items.assess.traffic_map}}",target="_blank")
            span 地理位置图

      header 价值分析
      article.content
        a(href="{{items.assess.trend}}",target="_blank")
          img(src="{{items.assess.trend}}", width="100%")

      header 有喜财富风控综合评估：
      article.content {{items.assess.assess_analyze}}







    section.content.list(v-if="typeId == 3")
      ul
        li
          div.title.cbox
            span.cl 投标人({{markrecord.length}}个)
            span.cl 摘标金额
            span.cl.sp 投标时间

        li(v-for="item in markrecord")
          div.cbox
            span.cl.txt {{ item.phone }}
            span.cl.txt ￥{{ item.bond }}
            span.cl.txt.sp {{ item.addtime }}


    section.content.list(v-if="typeId == 4")
      ul
        li
          div.title.cbox
            span.cl 期限
            span.cl 还款日期
            span.cl 状态
            span.cl 应还本息
            span.cl 应付罚息
        li
          div.cbox
            span.cl.txt. 1/6
            span.cl.txt 2016-10-20
            span.cl.txt 还已清
            span.cl.txt 10,000.00元
            span.cl.txt 10,000.00元

        li(v-for="item in items")
          div.cbox
            span.cl.txt 1/6
            span.cl.txt 2016-10-20
            span.cl.txt 还已清
            span.cl.txt 10,000.00元
            span.cl.txt 10,000.00元


    div.group-sub(v-if=" typeId == 5")


      span.txt 你将支付定金
      span.money {{items.bzj}}
        span.unt 元
      div.btn
        a.confirm( @click="submit()" ) 确认
        //button.confirm(type="submit") 确认
      //a.back(v-link="{path:'/group/'+groupId}") 返回
      div.note 摘标成功后, 客服在2个小时内<br>联系到您办理家访和抵押手续


    div(v-if="typeId == 6")
      header 房利宝介绍
      article.content
        p.mb10 1.房利宝项目为深圳房产抵押贷款。抵押率低于60%。
        p.mb10 2.“有喜财富”出具抵押物业市值评估参考意见有益借出资金的投资人决策参考；
        p.mb10 3.房利宝是指将房产抵押给投资人个人名下，年化收益14.4%，抵押率低于60%。该笔项目由投资人一人出资,投资人自行承担风险，产生逾期时不会有人垫付资金，因而不在“有喜财富”上公开发标；签订合同和办理抵押登记手续后，投资人直接将资金转账至借款人账户。“有喜财富”负责贷后管理和催收。欠息两个月以上，“有喜财富”协助投资人采取法律行动进行清收；
        p.mb10 4.投资人在房利宝项目列表看到有符合自己心意的可自由摘标，摘标需付项目金额3%的保证金，通过投标支付。
        p.mb10 5.摘标后“有喜财富”负责进行家访和现场考察并提供意见供投资人参考，投资人在参考了以上意见仍然决定借出款项时，须在2个工作日内来“有喜财富”办理相关手续；摘标后没有签《借款合同》《抵押合同》等相关法律文件可申请退回 3%的保证金。
        p.mb10 6.“有喜财富”协助房利宝投资人与借款人直接签订《借款合同》《抵押合同》等相关法律文件，并协助办理公证和抵押登记等手续； 签订上述合同后，投资人必须依合同约定发放贷款，否则将承担违约责任不可退回3%的保证金。成功放款后退回3%保证金。
        p 7.房利宝异地投资人来深办理抵押签合同等业务需自行解决交通食宿等费用。
    formpage(:url.sync="post_url", :rdata.sync="post_data")

</template>

<script>
import '../../assets/sass/invest/invest.scss'
//import {Api_Group_Detail} from '../../config/api'
import {Api_Tender, Api_Group_Detail, Api_Group_Apply, Api_Group_Verify, Api_Group_Submit} from '../../config/api'
import FormPage from '../../components/common/form'
import { Alert, Flexbox, FlexboxItem} from 'vux'

export default {

  data () {
    return {

      post_url: '',
      post_data:{},
      busy:false,

      typeId:'0',
      groupId:'',
      items:'',
      assess:'',
      markrecord:'',
      applyID:'',
      appyUrl:'',
      deposit:'',
      rdeposit:'',
      tback:false,
      busy:false,
      borrow_nid:"",
      money:"",
      header_txt:'',
      item:[],
      balance:0,
      total_money:'',
      status:''
    }
  },
  components: {
    formpage:FormPage,
    alert:Alert,
    flexbox:Flexbox,
    flexboxItem:FlexboxItem
  },
  methods: {
    back(){
      //this.$route.router.go('/invest/index?productype=group')
      window.history.back();
    },

    book(){
      var that = this;
      if(that.rdeposit==""){
        alert("请输入投资金额!");
        return false;
      }else{

        if(isNaN(that.rdeposit)){
           alert("你输入的不是数字");
           return false;
        }

        console.log(that.rdeposit);

        if( that.rdeposit < 500000){
           alert("摘金不小于50万");
           return false;
        }

        if( that.rdeposit % 10000!=0){
           alert("输入的数字要为1万的倍数!");
           return false;
        }

      }

      //this.$router.go('/group-sub/5?groupId='+this.groupId+'&deposit='+that.deposit);
      this.$router.go('/invest/group-sub/5?groupId='+this.groupId+'&deposit='+that.rdeposit);
      window.location.reload();
    },

    fetch(next){
      var that = this;
      this.$store.dispatch('setShowLoading', true);
      this.$http({url:Api_Group_Detail+'/name_no/'+this.groupId, method:'GET'}).then(function(rs){
        this.$store.dispatch('setShowLoading', false);
        that.items = rs.data.data;

        if(rs.data.data.markrecord.length == 0 )
          that.markrecord = false;
        else
          that.markrecord = rs.data.data.markrecord;
        //that.assess = rs.data.data.assess;
        next();
      })
    },


    apply(next){
      var that = this;
      this.$store.dispatch('setShowLoading', true);
      this.$http({url:Api_Group_Apply+'/name_no/'+this.groupId+'/setmoney/'+this.deposit, method:'GET'}).then(function(rs){
        this.$store.dispatch('setShowLoading', false);
        that.items = rs.data.data;
        that.applyID = rs.data.data.id;
        that.appyUrl = Api_Group_Submit;
        next();
      })
    },

    submit(){

      var that = this;
      if (that.busy) {
        return false;
      }
      //that.$children[0].show = true;
      that.busy = true;
      this.$store.dispatch('setShowLoading', true);
      this.$http({url:Api_Group_Verify+'&borrow_id='+this.applyID+'&setmoney='+this.deposit, method:'GET'}).then(function(rs){
        this.$store.dispatch('setShowLoading', false);
        that.busy = false;
        //that.$children[0].show = false;
        var status="", msg ="", link="", code="";


        if(typeof(rs.data)=="object"){
          status = rs.data.status, code = rs.data.code, msg = rs.data.msg;

          if(status){

            this.$children[0].show = true
            this.post_url = rs.data.action_url
            this.post_data.RequestData = rs.data.RequestData
            this.post_data.transCode = rs.data.transCode
            this.$children[0].submit();

          }else{
            alert(msg);
            if(code == '22221')
              this.$route.router.go('/login');
            //else
              //this.$route.router.go('/invest/group/'+this.groupId);
          }


        }else{

          var result = rs.data.split('}"');
          var rsa = JSON.parse(result[1]);
          console.log(rsa);

          status = rsa.status, msg = rsa.msg, link = rsa.msg;
          that.borrow_nid = rsa.borrow_nid, that.money = rsa.money;

          if( status == false){
            alert(msg);
            if(code == '22221')
              this.$route.router.go('/login');
            else
              this.$route.router.go('/invest/group/'+this.groupId);
          }else{

            //window.location.href = Api_Group_Submit+'&borrow_nid='+that.borrow_nid+'&money='+that.money;
            this.$children[0].show = true
            this.post_url = rs.data.action_url
            this.post_data.RequestData = rs.data.RequestData
            this.post_data.transCode = rs.data.transCode
            this.$children[0].submit();


          }

        }


      });
    },

    getorder:function(){
      var that = this;
      this.$http({ url:Api_Group_Detail+'/name_no/'+this.groupId, method:'POST' }).then(function(rs){
        //console.log(rs.data.data);
        that.item = rs.data.data;
        that.total_money = that.item.abstract1.account;
        that.status = rs.data.msg
        that.balance = rs.data.balance;
      })
    },


  },
  route:{
      activate ( transition ) {

        this.typeId = transition.to.params.typeId
        this.groupId = transition.to.query.groupId
        this.deposit = transition.to.query.deposit
        var that = this;
        if(this.typeId == 1){
          this.header_txt = "借款信息"
        }else if(this.typeId == 2){
          this.header_txt = "评估报告"
        }else if(this.typeId == 3){
          this.header_txt = "摘标记录"
        }else if(this.typeId == 4){
          this.header_txt = "我要分享"
        }else if(this.typeId == 5){
          this.header_txt = "确认支付定金"
        }else if(this.typeId == 6){
          this.header_txt = "房利宝介绍"
        }

        if(this.typeId=="5"){

          if(isNaN(this.deposit))
            this.tback = true;

          if( this.deposit < 500000)
             this.tback = true;

          if( this.deposit % 10000!=0 )
             this.tback = true;

          if(this.tback){
            alert("你输入的参数有误");
            this.$router.go('/invest/group/'+this.groupId);
            return false;
          }



          this.apply(function(){transition.next();that.getorder();})
        }
        else{
          this.fetch(function(){transition.next();that.getorder();})
        }

      }
  }

}
</script>
